<?php

namespace App\Services;

use Elastic\Elasticsearch\ClientBuilder;

class EsService
{
    private static $esClient;

    private function __construct()
    {
    }

    public static function getInstance(string $hosts, array $auth)
    {
        if (self::$esClient == null) {
            list($username, $password) = $auth;
            self::$esClient = ClientBuilder::create()
                ->setHosts(['host' => $hosts])
                ->setBasicAuthentication($username, $password)
                ->build();
            return self::$esClient;
        }
        return self::$esClient;
    }
}

